<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "order".
 *
 * @property integer $id
 * @property integer $omun
 * @property integer $uid
 * @property string $price
 * @property integer $status
 * @property string $name
 * @property integer $tel
 * @property string $phone
 * @property string $address
 * @property string $waybill
 * @property string $express
 */
class Order extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['omun', 'uid', 'price', 'status', 'name', 'tel', 'address'], 'required'],
            [['omun', 'uid', 'status', 'express', 'tel'], 'integer'],
            [['price'], 'number'],
            [['province', 'city'], 'string', 'max' => 8],
            [['community','type'], 'string', 'max' => 15],
            [['name','type'], 'string', 'max' => 10],
            [['phone'], 'string', 'max' => 20],
            [['address'], 'string', 'max' => 60],
            [['waybill'], 'string', 'max' => 15],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'omun' => '订单编号',
            'uid' => '会员名',
            'price' => '价格',
            'status' => '是否付款',
            'name' => '收货人',
            'tel' => '手机',
            'phone' => '电话',
            'address' => '详细地址',
            'waybill' => '发货单号',
            'express' => '快递公司',
            'paytime'=>'付款时间'
        ];
    }
    public function getOinfo(){
        return $this->hasMany(Oinfo::className(), ['oid'=>'id']);
    }
    public function getBom(){
        return $this->hasOne(Bom::className(), ['id'=>'express']);
    }
    public function getUser(){
        return $this->hasOne(User::className(), ['id'=>'uid']);
    }
    public function getPro(){
        return $this->hasOne(District::className(), ['id'=>'province']);
    }
    public function getCi(){
        return $this->hasOne(District::className(), ['id'=>'city']);
    }
    public function getCo(){
        return $this->hasOne(District::className(), ['id'=>'community']);
    }
}
